<?php

if (!function_exists('wdsxh_full_url')) {
    /**
     * 补全url
     */
    function wdsxh_full_url($url,$ret=false)
    {
        if (empty($url)) {
            return '';
        }

        if(stripos($url,',') !== false){
            $urls=explode(',',$url);
            foreach ($urls as &$row){
                $row=wdsxh_full_url($row);
            }
            return $urls;
        }

        if (!wdsxh_is_url($url)){
            $url = cdnurl($url, true);
            if (!wdsxh_is_url($url)) {
                $url = request()->domain() . $url;
            }
        }
        return $ret?array($url):$url;
    }
}
if (!function_exists('wdsxh_is_url')) {
    /**
     * 是否url
     */
    function wdsxh_is_url($url)
    {
        $preg = "/http[s]?:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is";
        if (preg_match($preg, $url)) {
            return true;
        } else {
            return false;
        }
    }
}

if (!function_exists('wdsxh_create_order')) {
    /**
     * 创建订单编号
     */
    function wdsxh_create_order()
    {
        return date('YmdHis') . str_pad(mt_rand(0, 1000), '4', '0', STR_PAD_LEFT);
    }
}

if (!function_exists('wdsxh_hide_mobile')) {
    /**
     * 隐藏手机号码中间位数
     */
    function wdsxh_hide_mobile($phone){
        $IsWhat = preg_match('/(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)/i',$phone);
        if($IsWhat == 1){
            return preg_replace('/(0[0-9]{2,3}[\-]?[2-9])[0-9]{3,4}([0-9]{3}[\-]?[0-9]?)/i','$1****$2',$phone);
        }else{
            return  preg_replace('/(1[358]{1}[0-9])[0-9]{4}([0-9]{4})/i','$1****$2',$phone);
        }
    }
}
if (!function_exists('wdsxh_get_openid')) {
    function wdsxh_get_openid($uid){
        $userBelongObj =\app\admin\model\wdsxh\UserBelong::where('user_id',$uid)->find();
        if($userBelongObj){
            return $userBelongObj->openid;
        }else{
            return '';
        }
    }
}
if (!function_exists('wdsxh_get_coceral')) {
    function wdsxh_get_coceral(){
        $Coceral=\app\admin\model\wdsxh\Introduce::get(1);
        if($Coceral){
            return $Coceral;
        }else{
            return '';
        }
    }
}

